package org.qf.web;

import org.qf.pojo.SmbmsProvider;
import org.qf.pojo.SmbmsUser;
import org.qf.service.SmbmsProviderService;
import org.qf.service.SmbmsUserService;
import org.qf.service.impl.SmbmsProviderServiceImpl;
import org.qf.service.impl.SmbmsUserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author young
 * @create 2021-01-15-11:27
 * @description
 */
@WebServlet(value = "/addProviderServlet")
public class AddProviderServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        SmbmsProvider smbmsProvider=new SmbmsProvider();

        String proCode=req.getParameter("proCode");
        String proName=req.getParameter("proName");
        String proContact=req.getParameter("proContact");
        String proPhone=req.getParameter("proPhone");
        String proAddress=req.getParameter("proAddress");
        String proFax=req.getParameter("proFax");
        String proDesc=req.getParameter("proDesc");

        smbmsProvider.setProCode(proCode);
        smbmsProvider.setProName(proName);
        smbmsProvider.setProContact(proContact);
        smbmsProvider.setProPhone(proPhone);
        smbmsProvider.setProAddress(proAddress);
        smbmsProvider.setProFax(proFax);
        smbmsProvider.setProDesc(proDesc);

//        HttpSession session=req.getSession();
//        SmbmsProvider providerSession = (SmbmsProvider) session.getAttribute("providerSession");
//        smbmsProvider.setCreatedBy(providerSession.getId());

        SmbmsProviderService smbmsProviderService=new SmbmsProviderServiceImpl();
        try {
            int i =smbmsProviderService.addProvider(smbmsProvider);
            if(i>0)
            {
                req.getRequestDispatcher("ProviderServlet").forward(req,resp);
            }else {
                resp.sendRedirect("providerAdd.jsp");

            }        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
